/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fhedu;

import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.game.GameCanvas;
import global.*;

/**
 *
 * @author Nishino
 */
public class ThongBaoChiTiet extends GameCanvas implements CommandListener {
     int focus=0;
    int i,j,k,i1;
    int y;
    int x;
    String noidungbinhluan="";
    Graphics g = getGraphics();
    CellList mangCell[]=new CellList[40];
    Graphics gO= getGraphics();
    Form binhluan=new Form("Bình luận");
    TextField txt=new TextField("Bình luận", "", 50, TextField.ANY);
    Command gui=new Command("Gửi",Command.SCREEN,1);
    Command quaylai=new Command("Quay lại",Command.SCREEN,1);
    ThongBaoChiTiet(){
        super(false);
        
        Ve();
    }
    void Ve(){
//        gO.setColor(128,255,255);
//        gO.fillRect(0, 0, 240, 300);
        gO.setFont(MyFont.fontnho);
        
        mangCell[0]=new CellList();
        mangCell[0].CellO(gO,0,0,240,20);
        gO.setColor(255,0,0);
        gO.drawLine(60,0,60,280);
        gO.drawString("Tiêu đề", 4, 2, Graphics.TOP|Graphics.LEFT);
        gO.drawString("Thông báo đóng tiền học",62,2, Graphics.TOP|Graphics.LEFT);
        
        mangCell[1]=new CellList();
        mangCell[1].CellO(gO,0,20,240,100);
        gO.drawString("Nội dung",4,22,Graphics.TOP|Graphics.LEFT);
        gO.drawString("Thời hạn đóng học phí ...",62, 22,Graphics.TOP|Graphics.LEFT);
        
        mangCell[2]=new CellList();
        mangCell[2].CellO(gO, 195,100,44,15);
        gO.drawString("Chi tiết", 198,100, Graphics.TOP|Graphics.LEFT);
        
        mangCell[3]=new CellList();
        mangCell[3].CellO(gO, 0,120,240,40);
        gO.drawString("Tài liệu",4,124,Graphics.TOP|Graphics.LEFT);
        gO.drawString("đính kèm", 4, 144, Graphics.TOP|Graphics.LEFT);

        mangCell[4]=new CellList();
        mangCell[4].CellO(gO, 0, 160,240, 20);
        gO.drawString("Bình luận", 4, 164, Graphics.TOP|Graphics.LEFT);
                
        mangCell[5]=new CellList();
        mangCell[5].CellO(gO,0,180,240,40);
        gO.drawString("Student A", 4, 184, Graphics.TOP|Graphics.LEFT);
        gO.drawString(global.noidungbinhluan.noidungbinhluan,64,184,Graphics.TOP|Graphics.LEFT);
                
        mangCell[6]=new CellList();
        mangCell[6].CellO(gO,0,220,240,60);
        gO.drawString("StudenB",4,224,Graphics.TOP|Graphics.LEFT);
        
        mangCell[7]=new CellList();
        mangCell[7].CellO(gO, 120, 280,120,20);
        gO.drawString("Danh sách bình luận", 123, 282, Graphics.TOP|Graphics.LEFT);
        
        mangCell[8]=new CellList();
        mangCell[8].CellO(gO,0, 280,55,20);
        gO.drawString("Quay Lại", 3, 283, Graphics.TOP|Graphics.LEFT);

        
        mangCell[focus].FocusCell(gO);
    }
   public void commandAction(Command c, Displayable d) {
        if(c==gui) {
            txt.setString(" " + txt.getString());
  
            global.noidungbinhluan.noidungbinhluan=txt.getString();
            FHEDU.display.setCurrent(new ThongBaoChiTiet());
        }
        else if (c==quaylai)
        {           
            {
                FHEDU.display.setCurrent(this);
            }
        }
   }
    public void keyPressed(int k)
    {
        Displayable NhapBinhLuan = null;
        switch(getGameAction(k))
        {
            case UP:
                if(focus>0)
                {
                 
                mangCell[focus].UnFocusCell(gO);
                mangCell[focus-1].FocusCell(gO);
                focus-=1;    
                flushGraphics();
                }
                break;
            case DOWN:
                if(focus<9)
                {
                mangCell[focus].UnFocusCell(gO);
                mangCell[focus+1].FocusCell(gO);
                focus+=1;    
                flushGraphics();
                }
                break;
            case FIRE:
                if(focus==4)
                {
                    mangCell=null;
                    gO=null;
                    binhluan.append(txt);
                    binhluan.addCommand(quaylai);
                    binhluan.addCommand(gui);
                    binhluan.setCommandListener(this);
                    
                    FHEDU.display.setCurrent(binhluan);
                }
               else
                    if(focus==8)
                    {                       
                   try {  
                            noidungbinhluan=null;
                            g = null;
                            mangCell=null;
                            gO= null;
                            binhluan=null;
                            txt=null;
                           gui=null;
                             quaylai=null;
                        FHEDU.display.setCurrent(new ThongBao());
                        }
                        catch (IOException ex) 
                            {
                                ex.printStackTrace();
                            }
                        }       
                    }
        } 
}
